$(function() {
	var mem_from = $.httpRootPath()+'api/web/load/member/preEntry';
	var org_form = $.httpRootPath()+ 'api/web/load/lead-in/roster';
	$("#MEM-FORM").attr("action",mem_from);
	$("#ORG-FORM").attr("action",org_form);

	var file = $('#update-file-hidden'),
		aim = $('#update-file-name');
	    file.on('change', function(e) {
		//e.currentTarget.files 是一个数组，如果支持多个文件，则需要遍历
		var name = e.currentTarget.files[0].name;
		aim.val(name);
	});

	$("#mem-up").click(function() {
		var m = document.getElementById("update-file-name")
		if(m.value == "") {
			layer.msg('请选择文件', {icon: 0});
			return false;
		} else {
			var fileName = $("#update-file-hidden").val();
			var gif = /\.xls/i;
			if(gif.test(fileName)) {
				$('#MEM-FORM').submit();
			} else {
				layer.msg('文件类型不正确，请核对后再导入！', {icon: 0});
				return false;
			}
		}
	});	

	$("#org-up").click(function() {
		var m = document.getElementById("update-file-name")
		if(m.value == "") {
			layer.msg('请选择文件', {icon: 0});
			return false;
		} else {
			var fileName = $("#update-file-hidden").val();
			var gif = /\.xls/i;
			if(gif.test(fileName)) {
				$('#ORG-FORM').submit();
			} else {
				layer.msg('文件类型不正确，请核对后再导入！', {
					icon: 0
				});
				return false;
			}
		}
	});

	//$("#mem-mould-down").click();
	$("#org-down").click(function() {
		var str = "";
		var oid = window.sessionStorage.getItem("organizeId");
		if(oid == null) {
			layer.msg('获取组织Id失败', {icon: 0});
			return false;
		} else {
			var rela = getRelation(oid);
			if(rela == "-1"){
				layer.msg('您没有权限', {icon: 0});
				return false;
			}
			str = $.httpRootPath()+"/api/web/load/i/"+ oid + "/down/org";
		    window.location.href = str;

			$.ajax({
				url: str,
				type: 'GET',
				dataType: 'json',
				cache: false,
				timeout: 15000,
				success: function(r) {
					layer.msg(r.msg, {
						icon: 0
					});
				},
				error: function(e) {
					console.log("下载异常");
				}
			})
		}
	});
	//$("#mem-export").click();
	$("#orgMem-down").click(function() {
		var str = "";
//		var oid = GetQueryString("oid");
		var oid = window.sessionStorage.getItem("organizeId");
		if(oid == null) {
			layer.msg('获取组织Id失败', {icon: 0});
			return false;
		} else {
			var rela = getRelation(oid);
			if(rela == "-1"){
				layer.msg('您没有权限', {icon: 0});
				return false;
			}
			str = $.httpRootPath()+"/api/web/load/i/"+ oid + "/export/mem";
			 window.location.href = str;
			
			$.ajax({
				url: str,
				type: 'GET',
				dataType: 'json',
				cache: false,
				timeout: 15000,
				success: function(r) {
					layer.msg(r.msg, {
						icon: 0
					});
				},
				error: function(e) {
						console.log("下载异常");
				}
			})

		}
	});
	//$("#mem-pre-mould-down").click();
	$("#mem-down").click(function() {
		var str  = $.httpRootPath()+"/api/web/load/member/preEntry";
		 window.location.href = str;
		$.ajax({
			url: str,
			type: 'GET',
			dataType: 'json',
			cache: false,
			timeout: 15000,
			success: function(r) {
				layer.msg(r.msg, {icon: 0});},
			error: function(e) {
					console.log("下载异常");
			}
		})
	});
})